<?php
/**
 * Created by PhpStorm.
 * User: Shroom Ari
 * Date: 11/20/14
 * Time: 11:23 AM
 */
class Minvoice extends MY_Model{
    public $table='invoice';

    function getInvoice($perpage,$offset){

        $query = $this->db->get('invoice',$perpage,$offset);
        return $query->result_array();
    }
    function getInvoiceById($id){
        $this->db->select('*');
        $this->db->from('invoice');
        $this->db->where('invoice_id',$id);
        $this->db->limit(1);
        $query = $this->db->get();
        return $query->result_array();
    }
    function countAll(){
        return $this->db->count_all('invoice');
    }

    function getInvoiceByUserId($uid){
        $this->db->select('*');
        $this->db->from('invoice');
        $this->db->where('user_id', $uid);
        $query = $this->db->get();
        return $query->result_array();
    }

    function updateInvoice($data,$id){
        $this->db->where("invoice_id",$id);
        if($this->db->update($this->table,$data))
            return TRUE;
        else
            return FALSE;
    }

    function createInvoice($data){
        if($this->db->insert('invoice', $data)){
            $insert_id = $this->db-> insert_id();
            return $insert_id;
        }
        else return false;
    }
}